home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / glass / glass.lha / GLASS / libtmc / fneedc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-11-06  |  1.9 KB  |  75 lines

  1. /* 
  2.    Copyright (C) 1990 C van Reewijk, email: dutentb.uucp!reeuwijk
  3.  
  4. This file is part of GLASS.
  5.  
  6. GLASS is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 1, or (at your option)
  9. any later version.
  10.  
  11. GLASS is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GLASS; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. /* File: fneedc.c
  21.  * Last modified: CvR
  22.  *
  23.  * Ensure that the next non-blank character in the input stream is the
  24.  * required character. Else complain.
  25.  */
  26.  
  27. /* Standard UNIX libraries. */
  28. #include <stdio.h>
  29. #include <ctype.h>
  30.  
  31. /* The header of this library */
  32. #include "tmc.h"
  33. #include "config.h"
  34.  
  35. /* Skip all `isspace()' characters, and try to character 'needc'.
  36.    Compose an error message in 'tmerrmsg' and return 1 if this
  37.    is not possible, else return 0.
  38.  */
  39. int tmfneedc( f, needc )
  40.  FILE *f;
  41.  int needc;
  42. {
  43.     register int c;
  44.     char charstr[15];
  45.     char needcharstr[15];
  46.  
  47.     if( fscanspace( f ) ) return( 1 );
  48.     c = getc( f );
  49.     if( c != needc ){
  50.     if( c == EOF ){
  51.         (void) sprintf( charstr, "EOF" );
  52.     }
  53.     else if( c>=' ' && c<='~' ){
  54.         (void) sprintf( charstr, "char '%c'", c );
  55.     }
  56.     else {
  57.         (void) sprintf( charstr, "char 0x%02x", c );
  58.     }
  59.     if( c>=' ' && c<='~' ){
  60.         (void) sprintf( needcharstr, "'%c'", needc );
  61.     }
  62.     else {
  63.         (void) sprintf( needcharstr, "0x%02x", needc );
  64.     }
  65.     (void) sprintf(
  66.         tmerrmsg,
  67.         "Expected character %s but got %s",
  68.         needcharstr,
  69.         charstr
  70.     );
  71.     return( 1 );
  72.     }
  73.     return( 0 );
  74. }
  75.